import 'package:flutter/material.dart'
    show BuildContext, State, StatefulWidget, Widget, debugPrint;
import 'package:flutter_mvvm_demo/base/base_view_model.dart';
import 'package:flutter_mvvm_demo/widget/loding/loading_widget.dart';
import 'package:provider/provider.dart';

///
/// 基础 BaseState 抽象类
///
abstract class BaseState<T extends StatefulWidget, M extends BaseViewModel>
    extends State<T> {
  late M viewModel;
  late String pageName;

  @override
  Widget build(BuildContext context) {
    return build(context);
  }

  Widget initView() {
    return Consumer<M>(builder: (cxt, provider, _) {
      return viewModel.isLoading ? const LoadingWidget() : buildView();
    });
  }

  Widget buildView();

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    debugPrint("didChangeDependencies:$pageName界面");
  }

  @override
  void didUpdateWidget(covariant T oldWidget) {
    // TODO: implement didUpdateWidget
    super.didUpdateWidget(oldWidget);
    debugPrint("didUpdateWidget: $pageName界面");
  }

  @override
  void deactivate() {
    // TODO: implement deactivate
    super.deactivate();
    debugPrint("deactivate:$pageName界面");
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    debugPrint("dispose 离开$pageName界面");
    debugPrint("销毁$pageName界面");
  }
}
